import { getStore, setStore } from '@/util/store'

import { msgNum } from '@/api/message/my-msg'

const logs = {
  state: {
    unreadNum: getStore({ name: 'unreadNum' }) || 0,
  },
  actions: {
    // 获取未读消息
    getUnreadMsg({ state, commit }) {
      return new Promise((resolve, reject) => {
        msgNum().then((res) => {
          commit('UNREAD_MSG', {num: res.data.data})
          resolve()
        }).catch(error => {
          reject(error)
        })
      })
    }
  },
  mutations: {
    UNREAD_MSG: (state,params) => {
      state.unreadNum = params.num
      setStore({ name: 'unreadNum', content: state.unreadNum })
    }
  }

}

export default logs
